package com.qfedu.openplateform.manager.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.openplateform.manager.entity.Recharge;
import com.qfedu.openplateform.manager.entity.TableData;
import com.qfedu.openplateform.manager.entity.UserToken;
import com.qfedu.openplateform.manager.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LLFZH
 * @date 2021/10/27 20:59
 * @className TokenController
 * @description ：token控制层
 */
@RestController
public class TokenController {

    @Autowired
    private TokenService tokenService;

    @RequestMapping("/sys/token/table")
    public TableData findTokenByPage(@RequestParam(value = "page",required = false,defaultValue = "1")Integer pageNum,
                                     @RequestParam(value = "limit", required = false, defaultValue = "4")Integer pageSize,
                                     @RequestParam(value = "accessToken") String accessToken) {

        System.out.println("token = " + accessToken);
        PageHelper.startPage(pageNum, pageSize);

        List<UserToken> tokenList = tokenService.findAllToken(accessToken);

        PageInfo<UserToken> userTokenPageInfo = new PageInfo<>(tokenList);

        TableData<UserToken> userTokenTableData = new TableData<>();

        userTokenTableData.setData(userTokenPageInfo.getList());

        return userTokenTableData;
    }

    /**
     * 删除token
     * @param ids
     * @return
     */
    @RequestMapping("/sys/token/del")
    public TableData deleteUserTokenByIds(Integer[] ids) {
        tokenService.deleteUserTokenByIds(ids);

        TableData tableData = new TableData();
        return tableData;
    }

    @RequestMapping("/sys/token/update")
    public TableData updateToken(UserToken userToken) {
        tokenService.updateToken(userToken);
        System.out.println("userToken = " + userToken);

        TableData<Object> objectTableData = new TableData<>();

        return objectTableData;

    }

}
